/******************************************************************************
* File description: maintenanceui.cpp
* Function: 维护页面
* Current Version: 1.0.0
* Author: 张宇轩
* Date: 2024-08-28
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
#include "maintenanceui.h"

/**
 * @brief 构造函数
 */
MaintenanceUI::MaintenanceUI()
{
    this->setResizeMode(QQuickWidget::SizeRootObjectToView);
    this->setWindowTitle("");
    this->_rootContext = this->getContext();
    // 传入AnalysisConfigNewUI类
    this->rootContext()->setContextProperty("maintenanceUi", this);

    this->maintenanceOthersUi = new MaintenanceOthersUI();
    this->maintenanceOthersUi->setParent(this, Qt::Window | Qt::WindowCloseButtonHint);

    this->selfChecking = new DeviceSelfChecking();
    this->selfChecking->setParent(this, Qt::Window | Qt::WindowCloseButtonHint);

    if(QSysInfo::productType() == "windows")
    {
        qDebug() << "windows";
        this->maintenanceOthersUi->setWindowFlags(this->maintenanceOthersUi->windowFlags() & ~Qt::WindowContextHelpButtonHint);
        this->selfChecking->setWindowFlags(this->selfChecking->windowFlags() & ~Qt::WindowContextHelpButtonHint);
    }

    // 资源加载
    this->setSource(QUrl("qrc:/maintenance.qml"));
    this->_rootObj = this->getRootObject();
    if(_rootObj)
    {
        connect(_rootObj, SIGNAL(othersMaintenance()), this, SLOT(onMaintenanceOthers()));
        connect(_rootObj, SIGNAL(returnSig()), this, SIGNAL(returnSig()));
        connect(_rootObj, SIGNAL(selfChecking()), this, SLOT(onSelfChecking()));
    }
}

/**
 * @brief 析构函数
 */
MaintenanceUI::~MaintenanceUI() {}

/**
 * @brief getContext 获取qmlcontext
 * @return qmlContext
 */
QQmlContext* MaintenanceUI::getContext() const
{
    return this->rootContext();
}

/**
 * @brief getRootObject 获取rootObject
 * @return rootObject
 */
QObject* MaintenanceUI::getRootObject() const
{
    return (QObject*)this->rootObject();
}

/**
 * @brief 其他维护
 */
void MaintenanceUI::onMaintenanceOthers()
{
    maintenanceOthersUi->show();
}

/**
 * @brief 自检
 */
void MaintenanceUI::onSelfChecking()
{
    selfChecking->show();
}
